package club.itstudio.IContainer.controller.common;

import club.itstudio.IContainer.annotation.LoginRequired;
import club.itstudio.IContainer.entity.User;
import club.itstudio.IContainer.service.AuthService;
import club.itstudio.IContainer.util.Result;
import club.itstudio.IContainer.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName UserInfo
 * @Author alex
 * Date 2021/4/26 3:48 下午
 * Version 1.0
 **/
@RestController
@RequestMapping("/userinfo")
public class UserInfo {

    private AuthService authService;

    @GetMapping
    @LoginRequired
    public Result getUserInfo() {
        User user = authService.threadLocalUsers.get();
        return ResultUtil.success(user);
    }

    @Autowired
    public void setAuthService(AuthService authService) {
        this.authService = authService;
    }
}
